/*
 * Copyright (C) 2012 Google Inc.  All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * Controls the pairingSession object.  The pairingSession object is created by
 * the googletvremote plugin during initialization.  The Pairing session is
 * used to make a secure connection with a Google TV.  This client program has
 * a 512 byte certificate that is sent to the Google TV and the Google TV issues
 * a 4 character challenge to this client.  If the client issues the correct
 * response the Google TV will consider the client with this certificate paired.
 * Once paired an Anymote session can be started for communication.
 * Pairing session functions include:
 *     pair(name, host, port, callback)
 *     setChallengeResponse(response)
 *     cancel()
 */


/** Pairing session object that this controller manages. */
var pairingSession;


/**
 * Attempts to pair with a Google TV at this ip address.  Upon sending a pair
 * request the session should receive events for SESSION_CREATED then
 * PERFORM_INPUT.  Once in the PERFORM_INPUT start the client should send a
 * challenge response.  If the challenge is correct a pairing will be made.
 * After a pairing is made a client must start an Anymote session to begin
 * actual communication.  The pairing session is only for pairing.
 * @param {string} googleTvIpAddress Ip address of the Google TV.
 */
var pairingSessionPair = function(googleTvIpAddress) {
  displayToast('pairingSessionPair not implemented');
  // TODO: Use the pairing session to pair with the Google TV.
  // TODO: Create a callback to listen for pairing events.  For example,
  //  googletvremote.pairing.EventType.SUCCESS success save the device.
  //  googletvremote.pairing.EventType.PERFORM_INPUT prepare user to enter PIN.
};


/**
 * Send a response to the Google TV's challenge.  The 4 character pin should be
 * displaying on the Google TV when this message is sent.
 * @param {string} challengeValue The 4 character challenge value (hexidecimal)
 *     to send to the Google TV to complete pairing.
 */
var sendChallengeResponse = function(challengeValue) {
  displayToast('sendChallengeResponse not implemented');
  // TODO: Send a challenge response.
};
